//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<RenderPipeline.h>
///	@path	~/src/graphics
///	@date	2008/04/04
///	@desc	Render pipeline management.

#pragma once

#include "xeres.h"

#include <vector>

#include "lib/math/color.h"
#include "lib/utilities/dep_stages.h"

#include "graphics/IDevice.h"
#include "graphics/ICanvas.h"
#include "graphics/IPass.h"
#include "graphics/IModel.h"
#include "graphics/RenderSet.h"

namespace xeres {

	/*! 
		\class	RenderPipeline
		\brief
	*/
	class RenderPipeline : public RenderSet
	{
	protected:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		RenderPipeline( void );

		/// \dtor
		~RenderPipeline( void );

		//@}

		/// \name Initialization & Finalization
		//@{

		/*!
			\brief		Initialize render manager.
		*/
		void Initialize( void );

		/*!
			\brief		Finalize render manager.
		*/
		void Finalize( void );

		//@}

		/// \name Render Manipulation
		//@{

		/*!
			\brief		Render pipeline with batches.
		*/
		void Render( void );

		/// \brief		Get overlay canvas.
		RefWeak<ICanvas> GetOverlay( void ) { return RefWeak<ICanvas>(m_overlay); }

		//@}

	public:

		/// \name Background & Overlays
		//@{

		/*!
			\brief		Set render wall paper.
		*/
		void SetWallpaper( RefWeak< ICanvas > wallpaper );

		/*!
			\brief		Set render overlay.
		*/
		void SetOverlay( RefWeak< ICanvas > overlay );

		//@}

	protected:

		/// \name Render Pass Management
		//@{

		/*!
			\brief		Set main pass.
		*/
		void SetMainPass( RefWeak< IPass > pass );

		/*! 
			\brief		Get main pass.
		*/
		RefWeak<IPass> GetMainPass( void );

		/*!
			\brief		Insert new pass into pipeline.
		*/
		bool InsertPass( const WString& name , const WString& dep ,
			RenderSetId sets , RefWeak< IPass > pass );


		/*!
			\brief		Clear sub pass.
		*/
		bool ClearSubPass( const WString& path );

		/*!
			\brief		Clear pipeline.
		*/
		void Reset( void );

		//@}

	private:

		// resolve passes
		void ResolvePasses( void );

	//@ data

		// wall paper canvas ( will be render before scene )
		Ref< ICanvas >		m_wallpaper;

		// overlay canvas ( will be render after scene )
		Ref< ICanvas >		m_overlay;

		// main pass
		Ref< IPass >		m_mainPass;

		// passes
		struct _Pass
		{
			RenderSetId		iset;
			Ref< IPass >	ipass;
		};

		// render pipelines
		std::vector<_Pass*>	m_pipeline;

		// states
		bool				m_reorderPipeline;
		bool				m_spare0[3];
	};

} // namespace xeres
